package com.src;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import android.widget.ImageView;

public class IndexActivity extends Activity {

	private final static Integer[] images = { R.drawable.l001, R.drawable.l002,
			R.drawable.l003, R.drawable.l004, R.drawable.l005, R.drawable.l006,
			R.drawable.l007, R.drawable.l008, R.drawable.l009, R.drawable.l010,
			R.drawable.l011, R.drawable.l012, R.drawable.l013 };

	private int currentImage = 0;
	private ImageView imageView = null;
	private int state = 0;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.indexmain);
		imageView = (ImageView) findViewById(R.id.imageView);
		final Handler handler = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case StaticValue.CHANGE_PICTURE:
					imageView.setImageResource(images[currentImage++]);
					if (currentImage >= 13) {
						currentImage = 0;
					}
					break;

				case StaticValue.CHANGE_LAYOUT:
					Intent intent = new Intent(IndexActivity.this,
							MainActivity.class);
					startActivity(intent);
					break;

				}
			}
		};

		new Timer().schedule(new TimerTask() {
			@Override
			public void run() {
				state++;
				Message msg = new Message();
				msg.what = StaticValue.CHANGE_PICTURE;
				handler.sendEmptyMessage(StaticValue.CHANGE_PICTURE);

				if (state == 14) {
					handler.sendEmptyMessage(StaticValue.CHANGE_LAYOUT);
				}
			}
		}, 0, 500);
	}
}
